package com.bluesky.plum.uimodels.render.swing.components.table;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class ObjectTableModel extends AbstractTableModel {

	List<Object[]> data=new ArrayList();

	protected int colCount;

	public ObjectTableModel(Object[][] data) {
		if (data != null) {
			for (Object[] os : data)
				this.data.add(os);

			if ( data.length == 0)
				colCount = 0;
			else
				colCount = data[0].length;
		}
		else{
			
			colCount = 0;
		}
	}

	public int getRowCount() {
		if (data == null)
			return 0;
		else
			return data.size();
	}

	public int getColumnCount() {
		return colCount;
	}

	public Object getValueAt(int row, int column) {
		return data.get(row)[column];
	}

	@Override
	public String getColumnName(int column) {

		return "a" + column;
	}

	public void addRow(Object[] row) {
		data.add(row);

		fireTableRowsInserted(data.size(), data.size());
	}

}
